package com.thingcom.chinamobile.exception;

import com.thingcom.base.util.R;
import com.thingcom.base.util.RRException;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 异常处理器
 *
 * @author zhoudb
 * @date 2019年06月03日 下午9:59:27
 */
@RestControllerAdvice
@Slf4j
public class RRExceptionHandler {

	/**
	 * 自定义异常
	 */
	@ExceptionHandler(RRException.class)
	public R handleRRException(RRException e){
		R r = new R();
		r.put("code", e.getCode());
		r.put("msg", e.getMessage());
		return r;
	}

	@ExceptionHandler(Exception.class)
	public R handleException(Exception e){
		log.error(e.getMessage(), e);
		return R.error(e.getMessage());
	}
}
